(defun permutations (items &aux result)
   (if items
       (dolist (item items result)
        (dolist (permutation (permutations (remove item items)))
          (push (cons item permutation) result)))
       '(nil)))

(defun make-no(n digits)
  (cond ((= digits 1) (car n))
	((or (null n) (< digits 1)) 0)
	(t (+ (* (car n) (expt 10 (1- digits))) (make-no (cdr n) (1- digits))))))

(defun is-pandigital(n)
  (or (= (* (make-no n 1) (make-no (cdr n) 4)) (make-no (nthcdr 5 n) 4))
      (= (* (make-no n 1) (make-no (cdr n) 3)) (make-no (nthcdr 4 n) 5))
      (= (* (make-no n 2) (make-no (cddr n) 2)) (make-no(nthcdr 4 n) 5))
      (= (* (make-no n 2) (make-no (cddr n) 3)) (make-no(nthcdr 5 n) 4))
      (= (* (make-no n 3) (make-no (cdddr n) 3)) (make-no (nthcdr 6 n) 3))
      ;(= (* (make-no n 4) (make-no (nthcdr 4 n) 1)) (make-no (nthcdr 5 n) 4))
      ))

(defun get-product (n)
  (cond ((= (* (make-no n 1) (make-no (cdr n) 4)) (make-no (nthcdr 5 n) 4)) (make-no (nthcdr 5 n) 4))
	((= (* (make-no n 2) (make-no (cddr n) 3)) (make-no(nthcdr 5 n) 4)) (make-no (nthcdr 5 n) 4))
	;((= (* (make-no n 4) (make-no (nthcdr 4 n) 1)) (make-no (nthcdr 5 n) 4)) (make-no (nthcdr 5 n) 4))
	))

(defun probl32()
  (reduce #'+ (delete-duplicates (mapcar #'get-product (delete-if-not #'is-pandigital (permutations '(1 2 3 4 5 6 7 8 9)))))))

